﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSunny.Admin.Controls
{
    public partial class EditLogo : System.Web.UI.UserControl
    {
        public string imagelogo;
        public int logoid;
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dt = DAL.DCollector.DBCollector.Instance.CallSQL1Param( "SELECT * FROM tbl_Logo", true);
            imagelogo = dt.Rows[0]["Logo_Image"].ToString();
            logoid = Convert.ToInt32(dt.Rows[0]["Logo_ID"].ToString());

        }

        protected void btnUpdateLogo_Click(object sender, EventArgs e)
        {
            if (fulImage.HasFile)
            {
                if (LIB.Validate.CheckFileType(fulImage.FileName))
                {
                    string link = fulImage.FileName;
                    LIB.Validate saveimage = new LIB.Validate();
                    saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Images/Logo/"), link, 800, fulImage.PostedFile.InputStream);
                    string filePathLogo = "/Resources/Images/Logo/" + fulImage.FileName;

                    DAL.DHelpers.Column[] cl = new DAL.DHelpers.Column[2];
                    cl[0] = new DAL.DHelpers.Column("Logo_Image", filePathLogo, DAL.DHelpers.DataType.DataTypeSql.Nvarchar);
                    cl[1] = new DAL.DHelpers.Column("Logo_Date", DateTime.Now.Year+":"+DateTime.Now.Month+":"+DateTime.Now.Day, DAL.DHelpers.DataType.DataTypeSql.Varchar);

                    string colWhere = "Logo_ID";

                    string  colValue = logoid.ToString();

                    DAL.DCollector.DBCollector.Instance.StoredUpdate("tbl_Logo", cl, colWhere, colValue);
                    Response.Redirect("/Admin/Index.aspx?panel=7&sub=0");
                }
                else
                {
                    Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Bạn vui lòng upload ảnh...')</script>");
            }
        }
    }
}